function GetSubCat()
{
	var cat_id		= $("#cat_id").val();
	var base_url	= $('#base_url').val();
	$("#subsubcat_id").attr('disabled', 'disabled');
	if (cat_id != "")
	{
		$("#subcat_id").removeAttr('disabled');
		$("#price_id").removeAttr('disabled');
		$.ajax({
			type: "POST",
			url: base_url + 'admins/admin_product/getsubcat',
			data: {cat_id: cat_id},
			dataType: "text",
			beforeSend: function(xhr) 
			{
				xhr.setRequestHeader("Ajax-Request", "true");
			},
			success: function(response) 
			{
				$("#subcat_id").html(response);
			}
		});
	}
	else
	{
		$("#subcat_id").attr('disabled', 'disabled');
		$("#price_id").attr('disabled', 'disabled');
		$("#subcat_id").html('<option value="">=== Chọn nhu cầu ====</option>');
		$("#subsubcat_id").html('<option value="">=== Chọn chủng loại ====</option>');
		$("#price_id").html('<option value="">=== Chọn giá ====</option>');
	}
}

function GetSubSubCat()
{
	var subcat_id	= $("#subcat_id").val();
	var base_url	= $('#base_url').val();
	if (subcat_id != "")
	{
		$("#subsubcat_id").removeAttr('disabled');
		$.ajax({
			type: "POST",
			url: base_url + 'admins/admin_product/getsubsubcat',
			data: {subcat_id: subcat_id},
			dataType: "text",
			beforeSend: function(xhr) 
			{
				xhr.setRequestHeader("Ajax-Request", "true");
			},
			success: function(response) 
			{
				$("#subsubcat_id").html(response);
			}
		});
	}
	else
	{
		$("#subsubcat_id").attr('disabled', 'disabled');
		$("#subsubcat_id").html('<option value="">=== Chọn chủng loại ====</option>');
	}
}

function GetDistinct()
{
	var province_id	= $("#province_id").val();
	var base_url	= $('#base_url').val();
	if (province_id != "")
	{
		$("#distinct_id").removeAttr('disabled');
		$.ajax({
			type: "POST",
			url: base_url + 'admins/admin_product/getdistinct',
			data: {province_id: province_id},
			dataType: "text",
			beforeSend: function(xhr) 
			{
				xhr.setRequestHeader("Ajax-Request", "true");
			},
			success: function(response) 
			{
				$("#distinct_id").html(response);
			}
		});
	}
	else
	{
		$("#distinct_id").attr('disabled', 'disabled');
		$("#distinct_id").html('<option value="">=== Chọn Quận/Huyện ====</option>');
	}
}

$(document).ready(function() 
{
	$('#chkaccept').click(function()
	{
		var chkaccept = $(this).attr("checked");
        if (chkaccept == true)
        {
        	$("#cmdpost").removeAttr('disabled');
        	$("#cmdpost").css('background', 'url(images/sites/button_dangtin3.png) top left no-repeat');
        }
        else
        {
        	$("#cmdpost").attr('disabled', 'disabled');
        	$("#cmdpost").css('background', 'url(images/sites/button_dangtin.png) top left no-repeat');
        }
	});
});

function checkfrmpost()
{
	var chkaccept 	= $("#chkaccept").attr("checked");
	if (chkaccept	== false)
	{
		return false;
	}
	var txttitle	= $("#txttitle").val();
	if (txttitle	== "")
	{
		$("#error_title").css('display', 'block');
		$("#txttitle").focus();
		return false;
	}
	else
		$("#error_title").css('display', 'none');
	
	var txtphone	= $("#txtphone").val();
	if (txtphone	== "")
	{
		$("#error_phone").css('display', 'block');
		$("#txtphone").focus();
		return false;
	}
	else
		$("#error_phone").css('display', 'none');
	
	var select_cat1	= $("#select_cat1").val();
	if (select_cat1	== "")
	{
		$("#error_cat").css('display', 'block');
		$("#select_cat1").focus();
		return false;
	}
	else
		$("#error_cat").css('display', 'none');
	
	var select_subcat	= $("#select_subcat").val();
	if (select_subcat	== "")
	{
		$("#error_subcat").css('display', 'block');
		$("#select_subcat").focus();
		return false;
	}
	else
		$("#error_subcat").css('display', 'none');
	
	var select_city	= $("#select_city").val();
	if (select_city	== "")
	{
		$("#error_city").css('display', 'block');
		$("#select_city").focus();
		return false;
	}
	else
		$("#error_city").css('display', 'none');
}